import os
import xml.etree.cElementTree as ET
from flask import Flask, request, url_for,render_template
from datetime import datetime

def Message(getXML):
    print("*"*80)
    xml=ET.fromstring(getXML)
    msgType=xml.find('MsgType').text
    if  msgType=="text" :
        print(getXML)
        print('文本消息:')
        toUser=xml.find('ToUserName').text
        fromUser=xml.find('FromUserName').text
        createTime=datetime.fromtimestamp(int(xml.find('CreateTime').text))
        content=xml.find('Content').text
        now=int(datetime.now().timestamp())
        print('-'*80)
        print("公众号：%s"%toUser)
        print("用户： %s"%fromUser)
        print("发送时间：%s"%createTime)
        print("内容：%s"%content)
        print('-'*80)
        print("*"*80)
        return render_template('text.xml', toUser=fromUser,fromUser=toUser,createTime=now)
    elif msgType=="image":
        print('图片消息:')

    elif msgType=="voice":
        print('音频消息:')

    elif msgType=="video":
        print('视频消息:')

    elif msgType=="shortvideo":
        print('小视频消息:')

    elif msgType=="location":
        print('地理位置消息:')

    elif msgType=="link":
        print('链接消息:')

    else:
        print("未知消息")
